home *** CD-ROM | disk | FTP | other *** search
- /*
- Terminal 2.2
- "Script.c"
- */
-
- #include "Compatibility.h"
- #include "Interp.h"
- #include "File.h"
- #include "FormatStr.h"
- /*#include "PubTools.h"*/
-
- /* ----- beep() -------------------------------------------------------- */
-
- static INTEGER SI_beep(INTEGER params[])
- {
- #pragma unused(params)
- Sys_Beep(1);
- return 0;
- }
-
-
- /* ----- string = new(size) -------------------------------------------- */
-
- static INTEGER SI_new(INTEGER params[])
- {
- return (INTEGER)malloc(params[0]);
- }
-
- /* ----- free(string) -------------------------------------------------- */
-
- static INTEGER SI_free(INTEGER params[])
- {
- free((char *)params[0]);
- return 0;
- }
-
- /* ----- result = strcat(s1, s2) --------------------------------------- */
-
- static INTEGER SI_strcat(INTEGER params[])
- {
- register Byte *s1 = (Byte *)params[0];
- register Byte *s2 = (Byte *)params[1];
-
- strcat((char *) s1, (char *) s2);
- return (INTEGER) s1;
- }
-
- /* ----- result = strcmp(s1, s2) --------------------------------------- */
-
- static INTEGER SI_strcmp(INTEGER params[])
- {
- register Byte *s1 = (Byte *)params[0];
- register Byte *s2 = (Byte *)params[1];
-
- while (tolower(*s1) == tolower(*s2)) {
- if (!*s1)
- break;
- s1++;
- s2++;
- }
- return (INTEGER)(tolower(*s1) - tolower(*s2));
- }
-
- /* ----- result = strcpy(s1, s2) --------------------------------------- */
-
- static INTEGER SI_strcpy(INTEGER params[])
- {
- register Byte *s1 = (Byte *)params[0];
- register Byte *s2 = (Byte *)params[1];
-
- strcpy((char *) s1, (char *) s2);
- return (INTEGER) s1;
- }
-
- /* ----- puts(s1) --------------------------------------- */
-
- static INTEGER SI_puts(INTEGER params[])
- {
- register Byte *s1 = (Byte *)params[0];
- puts((char *) s1);
- return 0;
- }
-
- /* ----- i = val(str) -------------------------------------------------- */
-
- static INTEGER SI_val(INTEGER params[]) /* Convert string to integer */
- {
- return atoi((char *) params[0]);
- }
-
- /* ----- str = itoa(i) -------------------------------------------------- */
-
- static INTEGER SI_itoa(INTEGER params[]) /* Convert string to integer */
- {
- static char s[256];
- sprintf(s, "%ld", params[0]);
- return (INTEGER) s;
- }
-
- /* ----- result = display(template, ...) ------------------------------- */
-
- static INTEGER SI_display(INTEGER params[])
- {
- register INTEGER result;
- Byte s[256];
-
- if (params[0]) {
- SFormatStr(s, (Byte *)params[0], ¶ms[1]);
- result = Display(s);
- } else { /* No formatting */
- result = Display((Byte *)params[1]);
- }
- return result;
- }
-
- /* ----- format(string, template, ...) --------------------------------- */
-
- static INTEGER SI_format(INTEGER params[])
- {
- SFormatStr((Byte *)params[0], (Byte *)params[1], ¶ms[2]);
- return 0;
- }
-
- /* ----- view(string) --------------------------------- */
-
- /*static INTEGER SI_view(INTEGER params[])*/
- /*{*/
- /*PubTypePtr p;*/
- /*INTEGER ret;*/
- /* if (!PubGet(&p, "\0", (char *) params[0])) {*/
- /* ret = PubView(p);*/
- /* free (p);*/
- /* return ret;*/
- /* }*/
- /* else return PE_PUBINFO_NOT_FOUND;*/
- /*}*/
-
- /* ----- Script intrinsic functions ------------------------------------ */
-
- INTRINSIC Intrinsics[] = {
- (Byte *)"beep", SI_beep,
- (Byte *)"display", SI_display,
- (Byte *)"format", SI_format,
- (Byte *)"printf", SI_display,
- (Byte *)"sprintf", SI_format,
- (Byte *)"free", SI_free,
- (Byte *)"itoa", SI_itoa,
- (Byte *)"new", SI_new,
- (Byte *)"puts", SI_puts,
- (Byte *)"stack", SI_stack, /* Defined in Interp.c */
- (Byte *)"strcat", SI_strcat,
- (Byte *)"strcmp", SI_strcmp,
- (Byte *)"strcpy", SI_strcpy,
- (Byte *)"val", SI_val,
- /* (Byte *)"view", SI_view,*/
- 0, 0
- };
-